<template>
	<view class="page">
		<view class="wd710">
			<!-- 	<view class="title_h3_reload">
			<text>应用:</text>
				<uni-icons type="refreshempty" size="20" @click="refreshMenu"></uni-icons>
			</view> -->

			<uni-grid class="gaid-box" :column="3" :showBorder="false">
				<uni-grid-item v-for="item in outInlist" :key="item.sTypeCode">
					<view class="grid-item" @click="gosType(item)">
						<image :src="baseUrl + '/icon/' + item.iImageIndex" class="menu-img"></image>
						<text>{{ item.sTypeName }}</text>
					</view>
				</uni-grid-item>
			</uni-grid>
			<uni-grid class="gaid-box" :column="3" :showBorder="false">
				<uni-grid-item v-for="item in findList" :key="item.sTypeCode">
					<view class="grid-item" @click="gosList(item)">
						<image :src="baseUrl + '/icon/' + item.iImageIndex " class="menu-img"></image>
						<text>{{ item.sTypeName }}</text>
					</view>
				</uni-grid-item>
			</uni-grid>
			<uni-grid :column="3" :showBorder="false">
				<uni-grid-item v-for="item in appList" :key="item.sTypeCode">
					<view class="grid-item" @click="handleGridClick(item)">
						<image :src="baseUrl + '/icon/' + item.iImageIndex " class="menu-img"></image>
						<text>{{ item.sTypeName }}</text>
					</view>
				</uni-grid-item>
			<!-- 	<uni-grid-item>
					<view class="grid-item" @click="goCustomer">
						<image :src="baseUrl + '/icon/' + '/b-icon-16.png'" class="menu-img"></image>
						<text>客户上传</text>
					</view>
				</uni-grid-item> -->
			</uni-grid>
			
		</view>
	</view>
</template>

<script>
	import {
		filter
	} from "lodash";
	import fabricService from "@/api/auth/fabricService";
	import BASE_URL from './../../config.js'
	export default {
		data() {
			return {
				outInlist: [],
				findList: [],
				appList: [],
			}
		},
		computed: {
			baseUrl() {
      			return BASE_URL.staticUrl;
    		}
		},
		created() {
			this.init();
		},
		methods: {
			
			goCustomer() {
				uni.navigateTo({
					url: "/pages/subA/test/customer/CustomerMobileList"
				});
			},
			
			async init() {
				const menuList = uni.getStorageSync('menu');
				const scanList = filter(menuList, function(o) {
					return o.sType === "scan"
				});
				const findList = filter(menuList, function(o) {
					return o.sType === "find"
				});
				const appList = filter(menuList, function(o) {
					return o.sType === "code"
				});
				this.outInlist = scanList;
				this.findList = findList;
				this.appList = appList;
			},
			gosType(item) {
				uni.navigateTo({
					url: "/pages/subB/fabric/index",
					success: (res) => {
						res.eventChannel.emit('sendData', item);
					}
				});
			},
			gosList(item) {
				uni.navigateTo({
					url: "/pages/subB/fabric/list",
					success: (res) => {
						res.eventChannel.emit('sendData', item);
					}
				});
			},

			//动态传递路径
			handleGridClick(item) {
				if (item.sTypeCode) {
					let url = "";
					// 判断fabric或者reportWork路径的替换成/pages/subB/
					if (item.sTypeCode.indexOf('fabric') > -1 || item.sTypeCode.indexOf('reportWork') > -1) {
						url = item.sTypeCode.replace('/pages/', '/pages/subB/');
					}else{
						// 将item.sTypeCode中的/pages/ 替换成/pages/subA/
						url = item.sTypeCode.replace('/pages/', '/pages/subA/');
					}
	
					uni.navigateTo({
						url,
						success: (res) => {
							res.eventChannel.emit('sendData', item);
						}
					}); // 跳转页面
				} else {
					console.log('点击项数据:', item); // 自定义逻辑
				}
			},
			goTest() {
				uni.navigateTo({
					url: "/pages/subA/test/mobile/TestMobileList"
				});
			},
			onPullDownRefresh() { // 监听下拉刷新事件
				// console.log('下拉刷新触发');
				this.customRefresh(); // 执行自定义刷新方法
			},
			//下拉刷新
			customRefresh() {
				setTimeout(() => {
					fabricService.getMenu().then(res => {
						const menuList = res;
						const scanList = filter(menuList, function(o) {
							return o.sType === "scan"
						});
						const findList = filter(menuList, function(o) {
							return o.sType === "find"
						});
						const appList = filter(menuList, function(o) {
							return o.sType === "code"
						});
						this.outInlist = scanList;
						this.findList = findList;
						this.appList = appList;
						uni.showToast({
							title: "刷新成功",
							duration: 1000,
							icon: "success"
						});
					});
					uni.stopPullDownRefresh(); // 停止下拉刷新动画
				}, 1500);
			},
			refreshMenu() {
				uni.showModal({
					title: '刷新菜单',
					content: '是否重新加载菜单',
					success: (res) => {
						if (res.confirm) {
							fabricService.getMenu().then(res => {
								const menuList = res;
								const scanList = filter(menuList, function(o) {
									return o.sType === "scan"
								});
								const findList = filter(menuList, function(o) {
									return o.sType === "find"
								});
								const appList = filter(menuList, function(o) {
									return o.sType === "code"
								});
								this.outInlist = scanList;
								this.findList = findList;
								this.appList = appList;
								uni.showToast({
									title: "刷新成功",
									duration: 1000,
									icon: "success"
								});
							});
						}
					}
				});
			}
		}
	}
</script>

<style scoped lang="scss">
	.page {
		// padding-top: 20rpx;
	}

	.title_h3_reload {
		width: 710rpx;
		margin: 10rpx auto;
		display: flex;
		justify-content: space-between;
		font-size: 32rpx;
		font-weight: bold;
	}

	.wd710 {
		width: 710rpx;
		margin: 0 auto;
	}

	// .gaid-box {
	// 	min-height: 244rpx;
	// }

	.menu-img {
		width: 120rpx;
		height: 120rpx;
	}

	.grid-item {
		// box-shadow: 0 1px 4px #f9f9f9, 1px 1px 40px rgba(0,0,0,.06);
		width: 80%;
		height: 80%;
		margin: auto;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		font-size: 28rpx;

		text {
			margin-top: 10rpx;
		}
	}
</style>